#define _CRT_SECURE_NO_WARNINGS

#include"Stack.h"

typedef struct A
{
	struct zb a;
	int f;
}A;

//void zmgdg()
//{
//	if()
//}

void z(A*sb,int n)
{
	switch (n)
	{
	case 1: 
		(sb->a.x)++;
		break;
	case 2:
		(sb->a.y)++;
		break;
	case 3:
		(sb->a.x)--;
		break;
	case 4:
		(sb->a.y)--;
		break;
	}
}
bool zmg(int a[10][10], A* sb, ST* b)
{
	if (a[sb->a.y][sb->a.x + 1] != 1)
	{
		z(sb, 1);
		StackPush(b, &sb->a);
		if (a[sb->a.y][sb->a.x] == 2)
			return true;
		a[sb->a.y][sb->a.x] = 1;
		zmg(a, sb, b);
	}
	else if (a[sb->a.y + 1][sb->a.x] != 1)
	{
		z(sb, 2);
		StackPush(b, &sb->a);
		if (a[sb->a.y][sb->a.x] == 2)
			return true;
		a[sb->a.y][sb->a.x] = 1;
		zmg(a, sb, b);
	}
	else if (a[sb->a.y][sb->a.x - 1] != 1)
	{
		z(sb, 3);
		StackPush(b, &sb->a);
		if (a[sb->a.y][sb->a.x] == 2)
			return true;
		a[sb->a.y][sb->a.x] = 1;
		zmg(a, sb, b);
	}
	else if (a[sb->a.y-1][sb->a.x] != 1)
	{	
		z(sb, 4);
		StackPush(b, &sb->a);
		if (a[sb->a.y][sb->a.x] == 2)
			return true;
		a[sb->a.y][sb->a.x] = 1;
		zmg(a, sb, b);
	}
	else
	{
		StackPop(b);
		if (StackEmpty(b))
			return false;
		sb->a=StackTOP(b);
		zmg(a, sb, b);
	}
}


int main()
{
	int a[10][10] = {
		1,1,1,1,1,1,1,1,1,1,
		1,0,0,1,0,0,0,1,0,1,
		1,0,0,1,0,0,0,1,0,1,
		1,0,0,0,0,1,1,0,0,1,
		1,0,1,1,1,0,0,0,0,1,
		1,0,0,0,1,0,0,0,0,1,
		1,0,1,0,0,0,1,0,0,1,
		1,0,1,1,1,0,1,1,0,1,
		1,1,0,0,0,0,0,0,2,1,
		1,1,1,1,1,1,1,1,1,1
	};
	A sb = { 1,1,1 };
	ST b;
	StackInit(&b);
	StackPush(&b, &sb.a);
	a[1][1] = 1;
	zmg(a,&sb,&b);

	getchar();
	return 0;
}